﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using NLog;

namespace FileSharingHosting
{
    public partial class Login : System.Web.UI.Page
    {
        static readonly Logger _log = LogManager.GetCurrentClassLogger();

        protected void Page_Load(object sender, EventArgs e)
        {
            _log.Debug("Login page requested");
            if (IsPostBack)
            {
                var ubll = new Business.UsersBusinessLogic();
                Validate();
                if (IsValid)
                {
                    if (ubll.IsValidAuth(login.Text, password.Text))
                    {
                        _log.Debug(string.Format("User logged in (Login={0})",login.Text));
                        FormsAuthentication.RedirectFromLoginPage(login.Text, remember.Checked);
                    }
                    else
                    {
                        _log.Info(string.Format("User failed to login (Login={0})", login.Text));
                        invalid.Visible = true;
                    }
                }
                else
                {
                    _log.Debug("Data invalid");
                }
            }
        }
    }
}